package dji.ux.ext.setting.aircraft;

import androidx.annotation.NonNull;

import dji.keysdk.DJIKey;
import dji.keysdk.FlightControllerKey;
import dji.thirdparty.io.reactivex.Completable;
import dji.thirdparty.io.reactivex.Flowable;
import dji.ux.beta.base.DJISDKModel;
import dji.ux.beta.base.SchedulerProviderInterface;
import dji.ux.beta.base.WidgetModel;
import dji.ux.beta.base.uxsdkkeys.ObservableInMemoryKeyedStore;
import dji.ux.beta.util.DataProcessor;

public class BeginnerModeModel extends WidgetModel {
    private SchedulerProviderInterface schedulerProvider;
    private final DataProcessor<Boolean> newPlayerEnabledProcessor;

    public BeginnerModeModel(@NonNull DJISDKModel djiSdkModel,
                             @NonNull ObservableInMemoryKeyedStore keyedStore,
                             @NonNull SchedulerProviderInterface scheduletProviderInterface) {
        super(djiSdkModel, keyedStore);
        this.schedulerProvider = scheduletProviderInterface;
        newPlayerEnabledProcessor = DataProcessor.create(false);
    }

    public Flowable<Boolean> getNewPlayerEnabled() {
        return newPlayerEnabledProcessor.toFlowable();
    }

    public Completable setEnable(boolean isChecked) {
        DJIKey newPlayerEnabledKey = FlightControllerKey.create(FlightControllerKey.NOVICE_MODE_ENABLED);
        return djiSdkModel.setValue(newPlayerEnabledKey, isChecked).subscribeOn(schedulerProvider.io());
    }

    @Override
    protected void inSetup() {
        FlightControllerKey newPlayerEnabledKey =
                FlightControllerKey.create(FlightControllerKey.NOVICE_MODE_ENABLED);
        bindDataProcessor(newPlayerEnabledKey, newPlayerEnabledProcessor);
    }

    @Override
    protected void inCleanup() {

    }

    @Override
    protected void updateStates() {

    }
}
